package configuration

import (
	"encoding/json"
	"fmt"
	"kop/modules/configuration/client"
	"kop/util/log"
)

func init() {

	var b = client.Load("ItemTemplate")
	if err := json.Unmarshal(b, &ItemConfigs); err != nil {
		panic(err)
	}

	log.Info("Load ItemTemplate.json success.")
	//********************************************************************//

}

const (
	TypePackage itemType = 2
	KingRing    itemType = 5
	Captain     itemType = 6
	Maid        itemType = 7
)

// 道具配置
type (
	itemType int32

	ItemConfig struct {
		ItemID    int32    `json:"ID"` // 物品ID
		Type      itemType // 物品类型
		Quality   int32    // 物品品质
		NeedLevel int32    // 等级要求
		AwardID   int32    // 奖励ID
	}
)

var (
	ItemConfigs = map[int32]ItemConfig{}
)

func GetByItemID(itemID int32) ItemConfig {

	var conf, ok = ItemConfigs[itemID]
	if !ok {
		panic(fmt.Sprintf("ItemID not found [%d]", itemID))
	}

	return conf
}
